﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using static SimonGame.Enum.LightEnum;

namespace SimonGame.ViewModel
{
    public class PlaySimonGameViewModel : INotifyPropertyChanged
    {
        /// <summary>
        /// 事件
        /// </summary>
        public event EventHandler IEventHandler;

        public event PropertyChangedEventHandler PropertyChanged;

        private Light light;
        public void Update(Light light, int flash)
        {
            this.light = light;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(this.light.ToString()));
                Task.Factory.StartNew(state =>
                {
                    System.Threading.Thread.Sleep(flash);
                    this.light = Light.None;
                    PropertyChanged(this, new PropertyChangedEventArgs(state.ToString()));
                }, this.light);
            }
        }


        private string _status = "WATCH";

        public string Status
        {
            get
            {
                return _status;
            }
            set
            {
                _status = value;
                //DoNotify();
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Status"));
            }
        }

        /// <summary>
        /// 分数
        /// </summary>
        private int _score;
        public int Score
        {
            get
            {
                return _score;
            }
            set
            {
                _score = value;
                //DoNotify();
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Score"));
                if (_score > _highScore)
                {
                    _highScore = _score;
                    //DoNotify("HighScore");
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HighScore"));
                }
            }
        }

        /// <summary>
        /// 最高分
        /// </summary>
        private int _highScore;
        public int HighScore
        {
            get
            {
                return _highScore;
            }
        }

        private Visibility _restart = Visibility.Collapsed;

        public Visibility Restart
        {
            get
            {
                return _restart;
            }
            set
            {
                _restart = value;
                //DoNotify();
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Restart"));

            }
        }

        public string Green
        {
            get
            {
                return light == Light.Green ? "/Images/green.jpg" : "/Images/greenNull.png";
            }
        }

        public string Red
        {
            get
            {
                return light == Light.Red ? "/Images/red.jpg" : "/Images/redNull.png";
            }
        }

        public string Yellow
        {
            get
            {
                return light == Light.Yellow ? "/Images/yellow.jpg" : "/Images/yellowNull.png";
            }
        }

        public string Blue
        {
            get
            {
                return light == Light.Blue ? "/Images/blue.jpg" : "/Images/blueNull.png";
            }
        }
    }
}
